package com.bjpowernode.rbac.web.controller;

import com.bjpowernode.rbac.entity.Permission;
import com.bjpowernode.rbac.query.QueryObject;
import com.bjpowernode.rbac.service.PermissionService;
import com.bjpowernode.rbac.util.ReturnObject;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/*
 *
 * @author jy
 * @version 1.0
 * @date 2022/2/7 19:13
 */

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject queryObject){
        //调用业务层获取数据
        PageInfo<Permission> pageInfo = permissionService.selectPermissionByCondition(queryObject);
        //传到页面
        model.addAttribute("pageInfo",pageInfo);
        //跳转到页面
        return "permission/list";
    }

    @RequestMapping("/delete")
    public String delete(Long id){
        permissionService.delete(id);
        return "redirect:/permission/list";
    }

    @RequestMapping("/reload")
    @ResponseBody
    public ReturnObject reload(){
        permissionService.reload();
        return new ReturnObject();
    }
}
